<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
      <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" id="btn-save">保存文件</button>
      </div>
      <blockquote class="layui-elem-quote">启用自定义脚本需要在 config.sh 中将参数 EnableExtraShell 设置为 true! 此处编辑的内容将保存在 config/diy.sh</blockquote>
      <div class="container diffs wrapper" style="height: 70vh;">
        <textarea id="code" name="code"></textarea>
      </div>
    </div>
  </div>
  
  <script type="text/javascript">
    $(document).ready(function () {
      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        lineWrapping: false,
        styleActiveLine: true,
        matchBrackets: true,
        mode: "shell",
        theme: "dracula",
        keyMap: "sublime",
      });
      $.get("./api/config/diy", function (data) {
        editor.setValue(data);
      });
      $("#btn-save").click(function () {
          var confContent = editor.getValue();
          let timeStamp = (new Date()).getTime()
          $.post('./api/save?t=' + timeStamp, { content: confContent, name: "diy.sh" }, function (data) {
              layer.msg('保存成功~');
          });
      });
    });
    layui.use(["layer"], function () {
      var $ = layui.jquery,
        layer = layui.layer;
    });
  </script>
  